

if ( Skt.config.USE_UI ) {
	
	$('#requestFocusBtn').hide();
	$('#requestFocusBtn').click(function() {
		var room = Skt.sketchpad.getCurrentCanvas().getRoom();
		var roomList = room.getRoomList();
		if ( roomList != null && roomList._group != null )
			Skt.tvManager.requestRoomFocus(room.getId(), roomList._group.getName(), roomList._group.getGroupType());
	});

	$('#followingBtn').click(function() {
		Skt.bullshitMonitorFlag = !Skt.bullshitMonitorFlag;
		Skt.teacherMonitor.setFollowingEnabled(Skt.bullshitMonitorFlag, Skt.subjectVersion.id, Skt.activity.id);
		$('#followingBtn').toggleClass('label-primary label-warning');
		return true;
	});
	
	Skt.ui.show_dropzones = function(side) {
		$('#delete-zone').css('right', '').css('left', '');
		if (side == "left") {
			var w_gts = $('#groups-tasks-sidebar').width();
			$('#delete-zone').css('left', w_gts + 40 + "px").show();
		} else if (side == "right") {
			var w_was = $('#workareas-sidebar').width();
			$('#delete-zone').css('right', w_was + 40 + "px").show();
		}
	};
	
	Skt.ui.hide_dropzones = function() {
		$("#delete-zone").hide();
	};
	
	Skt.ui.show_editzones = function() {
		$('#edit-request-zone').css('right', '').css('left', '');
		var w_gts = $('#groups-tasks-sidebar').width();
		$('#edit-request-zone').css('left', w_gts + 40 + "px").show();
	};
	
	Skt.ui.hide_editzones = function() {
		$('#edit-request-zone').hide();
	};
	Skt.ui.hide_editzones();
	
	
	Skt.ui.change_active_tool_icon = function(btn, icon_name) {
		if (!icon_name) {
			icon_name = $(btn).find("i").attr('class');
		}
		$(".tools").find('.btn').removeClass('btn-selected');
		$(btn).addClass('btn-selected');
		$("#icon_active_tool").removeClass().addClass(icon_name);
	};
	
	Skt.ui.fixUserlistHeight = function() {
		$("#groups-tasks-sidebar-bottom").height(
				$(window).height() - $('#groups-tasks-sidebar-top').height());
	};

	window.onresize = function() {
		$("#editor").width(1054);
		$("#editor").height(600);
		Skt.ui.fixUserlistHeight();
	};
	
	window.onbeforeunload = function() {
		Skt.user_list.changeInstances(Skt.user.id, -1);
		if ( Skt.sketchpad.getCurrentCanvas() != null )
			Skt.sketchpad.getCurrentCanvas().getRoom().getRoomModerator().userLeave(Skt.user.id);
	};
	
	$("#delete-zone").hide().css("visibility","visible");
	$("#copy-zone").hide().css("visibility","visible");
	$("#paste-zone").hide().css("visibility","visible");
	
//	$('#force-view-btn').click(function() {
//	  $('#lock-view-icon').toggleClass('ui-icon-unlocked ui-icon-locked');
//	  $('#force-view-btn').toggleClass('label-primary label-warning');
//	});
	
	// miniminar/maximizar una barra de menu
	$(".show_hide_menu_btn").click(function() {
		var menu = $(this).parent();
		var icon = $(this).find(".icon_show_hide");
		if (menu.hasClass("hidden_menu")) {
			menu.removeClass("hidden_menu");
			icon.removeClass("icon-caret-down").addClass("icon-caret-up");
		} else {
			menu.addClass("hidden_menu");
			icon.removeClass("icon-caret-up").addClass("icon-caret-down");
		}
	});
	
	// boton logout
	$("#icon_signout").click(function() {
		if (Skt.user_list.getUser(Skt.user.id) != null) {
			Skt.user_list.removeUser(Skt.user.id);
		}
		window.location = Skt.basePath + '/logout';
	});
	
	// botones de menu de workspaces
	$("#add_room_personal").click(function() {
		Skt.model.addRoom('personal');
	});
	
	$("#add_room_groupal").click(function() {
		Skt.model.addRoom('groupal');
	});
	
	$("#tool_select").click(
		function() {
			var old_tool = Skt.sketchpad.getTool();
	
			var selectT = new L.SelectTool(Skt.sketchpad);
			Skt.sketchpad.tool(selectT);
	
			if (old_tool instanceof L.TextTool) {
				var selectedElementId = old_tool.getSelectedElementId();
				if (selectedElementId) {
					var elem = sketchpad.getCurrentCanvas().getElement(selectedElementId);
					selectT.setSelection([ elem ]);
				}
			}
			// change_active_tool_icon(this);
		}
	);
	
	$("#tool_pen").click(function() {
		if (!Skt.editingEnabled)
			return;
		var penT = new L.PenTool(Skt.sketchpad);
		Skt.sketchpad.tool(penT);
		// change_active_tool_icon(this);
	});
	
	$("#tool_erase").click(function() {
		if (!Skt.editingEnabled)
			return;
		Skt.sketchpad.removeSelectedElements();
	});
	
	$("#tool_text").click(function() {
		if (!Skt.editingEnabled)
			return;
		var textTool = new L.TextTool(Skt.sketchpad);
		Skt.sketchpad.tool(textTool);
		// change_active_tool_icon(this);
	});
	
	$('#tool_copy').click(function() {
		Skt.sketchpad.copy();
	});
	
	$('#tool_paste').click(function() {
		if (!Skt.editingEnabled)
			return;
		Skt.sketchpad.paste();
	});
	
	$('#tool_undo').click(function() {
		if (!Skt.editingEnabled)
			return;
		Skt.sketchpad.undo();
	});
	
	$('#tool_redo').click(function() {
		if (!Skt.editingEnabled)
			return;
		Skt.sketchpad.redo();
	});
	
	$('#tool_zoom_in').click(function() {
		Skt.sketchpad.getCurrentCanvas().zoomIn();
		Skt.sketchpad.tool(new L.PanTool(Skt.sketchpad));
		// change_active_tool_icon('#tool_move');
	});
	
	$('#tool_zoom_out').click(function() {
		var canvas = Skt.sketchpad.getCurrentCanvas();
		canvas.zoomOut();
		Skt.sketchpad.tool(new L.PanTool(Skt.sketchpad));
		// change_active_tool_icon('#tool_move');
	});
	
	$('#tool_move').click(function() {
		Skt.sketchpad.tool(new L.PanTool(Skt.sketchpad));
		// change_active_tool_icon(this);
	});
	
	$('#tool_colorpicker').simpleColor(
		{
			cellWidth : 40,
			cellHeight : 40,
			columns : 4,
			border : '1px solid #333333',
			buttonClass : 'button',
			boxWidth : "30px",
			boxHeight : "30px",
			parent : "tool_color",
			// colors: ["000000","808080","C0C0C0","800000","FF0000",
			// "808000","FFFF00","008000","00FF00","008080",
			// "00FFFF","000080","0000FF","800080","FF00FF"],
			// colors: [
			// "000000","555753","A40000","5C3566","204A87","4E9A06","8F5902","CE5C00","C4A000",
			// "2E3436","888A85","CC0000","75507B","3465A4",
			// "73D216","C17D11","F57900","EDD400"],
			colors : [ "111111", "A40000", "5C3566", "204A87", "555753",
					"CC0000", "75507B", "3465A4", "4E9A06", "8F5902",
					"CE5C00", "C4A000", "73D216", "C17D11", "F57900",
					"EDD400" ],
			callback : function(color) {
				if (!Skt.editingEnabled)
					return;
				Skt.sketchpad.toolOptions({
					color : color
				});
				$('#icon_active_tool').css("color", "#" + color);
			}
		});

	$('.simpleColorDisplay').html('&#9632;');
	$('.simpleColorDisplay').css('font-size','42px');
	$('.simpleColorDisplay').css('position','relative');
	$('.simpleColorDisplay').css('top','-6px');
	
	
	$('#tool_clear').click(function() {
		if (!Skt.editingEnabled)
			return;
		$("<p>Do you wish to delete all the content on the slide?</p>").dialog({
			resizable : false,
			title : "Confirmation",
			modal : true,
			buttons : {
				"Yes" : function() {
					Skt.sketchpad.clear();
					$(this).dialog("close");
				},
				"Cancel" : function() {
					$(this).dialog("close");
				}
			}
		});
	});
	
	Skt.ui.saveCanvas = function(canvas) {
		var image_b64 = canvas.toDataURL("image/png").replace("data:image/png;base64,", "");
//		console.log("image_b64");console.log(image_b64);
		var image_data = $.base64.atob(image_b64, false);
//		console.log("image_data");console.log(image_data);
		// Use typed arrays to convert the binary data to a Blob
		var arraybuffer = new ArrayBuffer(image_data.length);
		var view = new Uint8Array(arraybuffer);
		for (var i = 0; i < image_data.length; i++) 
			view[i] = image_data.charCodeAt(i) & 0xff;
		
		var blob = null;
		try {
			// This is the recommended method:
			blob = new Blob([ arraybuffer ], {
				type : 'application/octet-stream'
			});
		} catch (e) {
			console.log("catch!");
			var bb = new (window.WebKitBlobBuilder || window.MozBlobBuilder);
			bb.append(arraybuffer);
			blob = bb.getBlob('application/octet-stream');
		}
		// Use the URL object to create a temporary URL
		var date = new Date();
		var date_txt = $.datepicker.formatDate('dd.M.yy', date);
		var time_txt = date.getHours() + "." + date.getMinutes() + "." + date.getSeconds();
		saveAs(blob, "Slide_" + date_txt + "_" + time_txt + ".png");
	};
	
	$("#tool_export").click( function() {
		
		// the canvas calls to output a png
		var canvas = document.getElementById("canvas");
		
		if ( Skt.sketchpad.getCurrentCanvas() != null ) {
			var context = canvas.getContext('2d');
			var room = Skt.sketchpad.getCurrentCanvas().getRoom();
//			$('#canvas').css('background-image',room.getBackgroundImageCss());
			
			if ( room.getBackground() != null ) {
				var imageObj = new Image();
				imageObj.onload = function() {
					context.clearRect(0, 0, canvas.width, canvas.height);
					context.drawImage(imageObj, 0, 0, canvas.width, canvas.height);
					canvg('canvas', $("#editor").html(), {ignoreClear: true, ignoreDimensions: true});
					Skt.ui.saveCanvas(canvas);
				};
				imageObj.src = room.getBackgroundImageURL();
			} else {
				canvg('canvas', $("#editor").html());
				Skt.ui.saveCanvas(canvas);
			}
			
		}

//		canvg('canvas', $("#editor").html());
//		
//		var image_b64 = canvas.toDataURL("image/png").replace("data:image/png;base64,", "");
////		console.log("image_b64");console.log(image_b64);
//		var image_data = $.base64.atob(image_b64, false);
////		console.log("image_data");console.log(image_data);
//		// Use typed arrays to convert the binary data to a Blob
//		var arraybuffer = new ArrayBuffer(image_data.length);
//		var view = new Uint8Array(arraybuffer);
//		for (var i = 0; i < image_data.length; i++) 
//			view[i] = image_data.charCodeAt(i) & 0xff;
//		
//		var blob = null;
//		try {
//			// This is the recommended method:
//			blob = new Blob([ arraybuffer ], {
//				type : 'application/octet-stream'
//			});
//		} catch (e) {
//			console.log("catch!");
//			var bb = new (window.WebKitBlobBuilder || window.MozBlobBuilder);
//			bb.append(arraybuffer);
//			blob = bb.getBlob('application/octet-stream');
//		}
//		// Use the URL object to create a temporary URL
//		var date = new Date();
//		var date_txt = $.datepicker.formatDate('dd.M.yy', date);
//		var time_txt = date.getHours() + "." + date.getMinutes() + "." + date.getSeconds();
//		saveAs(blob, "Slide_" + date_txt + "_" + time_txt + ".png");
	
	});
	
		
	if (Skt.user.type == "teacher") {
		$("#tool_checkbox_good").click(function() {
			var checkbox_good_Tool = new L.CheckboxTool("good");
			Skt.sketchpad.tool(checkbox_good_Tool);
			// change_active_tool_icon(this);
		});
	
		$("#tool_checkbox_bad").click(function() {
			var checkbox_bad_Tool = new L.CheckboxTool("bad");
			Skt.sketchpad.tool(checkbox_bad_Tool);
			// change_active_tool_icon(this);
		});
	
		$("#add_room_screen").click(function() {
			Skt.model.addRoom('screen');
		});
	
		$("#add_room_question").click(function() {
			Skt.model.addRoom('question');
		});
	} else if (Skt.user.type == "student") {
		$("#tool_checkbox_good").hide();
		$("#tool_checkbox_bad").hide();
		$("#add_room_screen").hide();
		$("#add_room_question").hide();
		$("#sort_room_screen").hide();
		$("#sort_room_question").hide();
		$('#add_group').hide();
	}
	
	Hammer($("#editor")[0]).on("pinchout", function(event) {
		var center = {
			x : event.gesture.center.pageX,
			y : event.gesture.center.pageY
		};
		var panZoom = Skt.sketchpad.getCurrentCanvas()._panzoom;
		panZoom.applyZoom(1, center);
		event.preventDefault();
	});
	
	Hammer($("#editor")[0]).on("pinchin", function(event) {
		var center = {
			x : event.gesture.center.pageX,
			y : event.gesture.center.pageY
		};
		var panZoom = Skt.sketchpad.getCurrentCanvas()._panzoom;
		panZoom.applyZoom(-1, center);
		event.preventDefault();
	});
	
		
	$(".rooms_list").resizable({
		handles : { 's' : '.rooms_list_handler' },
		maxHeight : 300,
		resize : function(event, ui) {
			var height = $(this).height() - $(this).children(".rooms_list_handler").height();
			$(this).children(".rooms-ul").css("height", height);
		},
		stop : function(event, ui) {
			$(this).css("width", "100%");
		}
	});
	
	$("#rooms_list_groupal").resizable({
		handles : { 's' : '.rooms_list_handler' },
		maxHeight : 300,
		resize : function(event, ui) {
			var height = $(this).height() - $(this).children(".rooms_list_handler").height();
			$(this).children("#groupal-rooms-container").css("height", height);
		},
		stop : function(event, ui) {
			$(this).css("width", "100%");
		}
	});
	
	//menus desplegables laterales 
	$(function(){
	    $('#workareas-sidebar').tabSlideOut({
	        tabHandle: '#workareas-sidebar > .handle',  //class of the element that will become your tab
	        dragbar: '#workareas-sidebar > .dragbar',
	        pathToTabImage: Skt.basePath + '/resources/images/tab-slides.png',    //path to the image for the tab //Optionally can be set using css
	        imageHeight: '152px',                     //height of tab image           //Optionally can be set using css
	        imageWidth: '27px',                       //width of tab image            //Optionally can be set using css
	        tabLocation: 'right',                      //side of screen where tab lives, top, right, bottom, or left
	        speed: 300,                               //speed of animation
	        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
	        topPos: '0px',                          //position from the top/ use if tabLocation is left or right
	        leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
	        minSize: 152,                           //ancho minimo del sidebar en px
	        fixedPosition: true                      //options: true makes it stick(fixed position) on scroll
	    });
	
	    $('#groups-tasks-sidebar').tabSlideOut({
	        tabHandle: '#groups-tasks-sidebar > .handle',  //class of the element that will become your tab
	        dragbar: '#groups-tasks-sidebar > .dragbar',
	        pathToTabImage: Skt.basePath + '/resources/images/tab-users.png',    //path to the image for the tab //Optionally can be set using css
	        imageHeight: '152px',                     //height of tab image           //Optionally can be set using css
	        imageWidth: '27px',                       //width of tab image            //Optionally can be set using css
	        tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
	        speed: 300,                               //speed of animation
	        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
	        topPos: '0px',                          //position from the top/ use if tabLocation is left or right
	        leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
	        minSize: 295,                           //ancho minimo del sidebar en px
	        fixedPosition: true                      //options: true makes it stick(fixed position) on scroll
	    });
	});
	
	    
	$.fn.togglepanels = function() {
		return this.each(function() {
			$(this)
				.addClass("ui-accordion ui-accordion-icons ui-widget ui-helper-reset")
				.find("h3")
				.addClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-top ui-corner-bottom")
				.hover(function() { $(this).toggleClass("ui-state-hover"); })
				.prepend('<span class="ui-icon ui-icon-triangle-1-e"></span>')
				.click( function() {
					$(this).toggleClass("ui-accordion-header-active ui-state-active ui-state-default ui-corner-bottom")
						.find("> .ui-icon")
						.toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s")
						.end()
						.next()
							.slideToggle();
					return false;
				})
				.next()
					.addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom")
					.hide();
		});
	};
	
	
	$("#menu_accordion_left").togglepanels();
	$("#menu_accordion_right").togglepanels();

	
	
	
	
	
	
	$('#group-invite-alert').hide();
	
	$('#decline-invitation-btn').click(function(){
		Skt.groupsManager.dismissInvitation({ invitedId: Skt.user.id });
	});
	
	Skt.ui.invitationAcceptedCallback = function(params) {
		var group = params.group;

		if ( params.action == "addGroup" && group.getName() == Skt.invitedGroup.name && group.getOwnerId() == Skt.invitedGroup.ownerId ) {
			group.addMember(Skt.user.id);
			Skt.groupsManager.off('groupEvent', Skt.ui.invitationAcceptedCallback, null);
		}
	};
	
	$('#accept-invitation-btn').click(function(){
		Skt.groupsManager.on('groupEvent', Skt.ui.invitationAcceptedCallback, null);
		Skt.groupsManager.addNoteGroup(Skt.invitedGroup.name, Skt.invitedGroup.ownerId);
		Skt.groupsManager.dismissInvitation({ invitedId: Skt.user.id });
//		group.addMember(Skt.user.id);
//		$('#group-invite-alert').hide('fast');
	});

	
	$('#create-notes-group-btn').click(function() {
		var name = $('#new-notes-group-name').val();
		if ( name == null || name == "" || Skt.groupsManager.groupExists( name , 'note' ) ) {
			alert('The group name is already in use, plese use a different name.');
			return false;
		}
		Skt.groupsManager.addNoteGroup(name, Skt.user.id);
		$('#add-notes-group-modal').modal('hide');
	});

	$('#create-work-group-btn').click(function(){
		var type = $('input[name=add-type]:checked').val();
		
		if ( type == "1group" ) {
			
			var name = $('#new-work-group-name').val();
			if ( name == null || name == "" || Skt.groupsManager.groupExists( name , 'work' ) ) {
				alert('The group name is already in use, plese use a different name.');
				return false;
			}
			Skt.groupsManager.addWorkGroup(name, Skt.user.id);
			$('#add-group-modal').modal('hide');
			
		} else if  ( type == "ngroups" ) {
			
			var num = $('#groups-number-spinner').val();
			
			if ( num == null || num == "" ) {
				alert("Please input a number of groups to create");
				return false;
			}
			
			var i = 1;
			var j = 0;
			
			while( i <= num ) {
				var name = "Group " + (i+j);
//				if ( Skt.groupsManager.groupExists( name , 'work' ) ) {
//					++j;
//				} else {
					Skt.groupsManager.addWorkGroup(name, Skt.user.id);
					++i;
//				}
			}

			$('#add-group-modal').modal('hide');
			
		} else if ( type == "nevengroups") {

			var num = $('#even-groups-number-spinner').val();
			if ( num == null || num == "" ) {
				alert("Please input a number of groups to create");
				return false;
			}
			
			var i = 1;
			var j = 0;
			var groups = [];
			
			while( i <= num ) {
				var name = "Group " + (i+j);
//				if ( Skt.groupsManager.groupExists( name , 'work' ) ) {
//					++j;
//				} else {
					groups.push( Skt.groupsManager.addWorkGroup(name, Skt.user.id) );
					++i;
//				}
			}
			
			var users = Skt.user_list.getUsers();
			var l = 0;
			for( var k = 0; k < users.length; ++k ) {
				var user =  users[k];
				if ( user.rol != 'teacher' && !user.workGroupName ) {
					groups[l].addMember(user.id);
					l = (l + 1) % groups.length; 
				}
			}

			$('#add-group-modal').modal('hide');
			
		} else if ( type == "groupsofn" ) {
			
			var num = $('#quantity-groups-number-spinner').val();
			if ( num == null || num == "" ) {
				alert("Please input a number of members per group");
				return false;
			}
			
			num = Math.floor(Skt.user_list.getUsers().length / num);
			var i = 1;
			var j = 0;
			var groups = [];
			
			while( i <= num ) {
				var name = "Group " + (i+j);
//				if ( Skt.groupsManager.groupExists( name , 'work' ) ) {
//					++j;
//				} else {
//				}
				groups.push( Skt.groupsManager.addWorkGroup(name, Skt.user.id) );
				++i;
			}
			
			var users = Skt.user_list.getUsers();
			var l = 0;
			for( var k = 0; k < users.length; ++k ) {
				var user =  users[k];
				if ( user.rol != 'teacher' && !user.workGroupName ) {
					groups[l].addMember(user.id);
					l = (l + 1) % groups.length; 
				}
			}

			$('#add-group-modal').modal('hide');
			
		}
	});
	
	
	
	
	
	
	Skt.sketchpad.on('changeTool', function(tool_name) {
		var btn_tool_id = "";
		switch (tool_name) {
		case "select_tool":
			btn_tool_id = "#tool_select";
			break;
		case "pen_tool":
			btn_tool_id = "#tool_pen";
			break;
		//case "tool_erase": btn_tool_id = "#tool_erase"; break;
		case "text_tool":
			btn_tool_id = "#tool_text";
			break;
		//case "tool_copy": btn_tool_id = "#tool_copy"; break;
		//case 'tool_paste': btn_tool_id = "#tool_paste"; break;
		//case 'tool_undo': btn_tool_id = "#tool_undo"; break;
		//case 'tool_redo': btn_tool_id = "#tool_redo"; break;
		case 'pan_tool':
			btn_tool_id = "#tool_move";
			break;
		case 'tool_move':
			btn_tool_id = "#tool_move";
			break;
		//case 'tool_colorpicker': btn_tool_id = "#tool_colorpicker"; break;
		//case 'tool_clear': btn_tool_id = "#tool_clear"; break;
		case 'checkbox_tool_good':
			btn_tool_id = "#tool_checkbox_good";
			break;
		case 'checkbox_tool_bad':
			btn_tool_id = "#tool_checkbox_bad";
			break;
		}
		if (btn_tool_id != "") {
			Skt.ui.change_active_tool_icon(btn_tool_id);
		}
	}, this);
	
	
	Skt.ui.updateCurrentUsers = function(params) {
		var room = Skt.sketchpad.getCurrentCanvas().getRoom();
		var moderator = room.getRoomModerator();
		var currentlyEditing = moderator.getCurrentlyEditing(); 
		
		$('#concurrent-users-list').html('');
		var ownerId = moderator.getRoom().getOwnerId();
		for ( var i = 0; i < currentlyEditing.length; ++i ) {
			var userId = currentlyEditing[i];
			var user = Skt.user_list.getUser(userId);
			if ( ownerId != user.id && ownerId == Skt.user.id && ( room.getType() == 'screen' || room.getType() == 'question' ) )
				$('#concurrent-users-list').append('<li class="label label-default" data-id="' + user.id + '" data-name="' + user.name + '" onclick="Skt.sketchpad.getCurrentCanvas().getRoom().getRoomModerator().requestEditorRemoval(Skt.user.id,\'' + user.id + '\');">' + user.name + '&nbsp;X</li>');
			else
				$('#concurrent-users-list').append('<li class="label label-default" data-id="' + user.id + '" data-name="' + user.name + '">' + user.name + '</li>');
		}
		
		if ( moderator.canEdit(Skt.user.id) )
			Skt.ui.enableEditing();
		else
			Skt.ui.disableEditing();
	};
	
	Skt.sketchpad.on('currentUsersChanged', Skt.ui.updateCurrentUsers, null);
	
	
	$('#import-loading-icon').hide();
   
//    $(".import-slides-icon").click(function() {
// 	   $('#activity_id_input').val($(this).data('id'));
// 	   return true;
//    });
   
    $('#import-slides-form').submit(function(){
 	   $('#import-loading-icon').show('fast');
 	   return true;
    });
	
	
}

Skt.ui.refreshEditingEnabled = function() {
	if (Skt.editingEnabled) {
		$('#tools #tool_pen').removeClass('tool-disabled');
		$('#tools #tool_erase').removeClass('tool-disabled');
		$('#tools #tool_text').removeClass('tool-disabled');
		$('#tools #tool_paste').removeClass('tool-disabled');
		$('#tools #tool_undo').removeClass('tool-disabled');
		$('#tools #tool_redo').removeClass('tool-disabled');
		$('#tools #tool_color').removeClass('tool-disabled');
		$('#tools #tool_clear').removeClass('tool-disabled');
		$('#tools #tool_checkbox_good').removeClass('tool-disabled');
		$('#tools #tool_checkbox_bad').removeClass('tool-disabled');
	} else {
		$('#tools #tool_pen').addClass('tool-disabled');
		$('#tools #tool_erase').addClass('tool-disabled');
		$('#tools #tool_text').addClass('tool-disabled');
		$('#tools #tool_paste').addClass('tool-disabled');
		$('#tools #tool_undo').addClass('tool-disabled');
		$('#tools #tool_redo').addClass('tool-disabled');
		$('#tools #tool_color').addClass('tool-disabled');
		$('#tools #tool_clear').addClass('tool-disabled');
		$('#tools #tool_checkbox_good').addClass('tool-disabled');
		$('#tools #tool_checkbox_bad').addClass('tool-disabled');
	}
};

Skt.ui.enableEditing = function() {
	Skt.editingEnabled = true;
	Skt.ui.refreshEditingEnabled();
};

Skt.ui.disableEditing = function() {
	$("#tool_select").click();
	Skt.editingEnabled = false;
	Skt.ui.refreshEditingEnabled();
};



